package wschat.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.socket.config.WebSocketMessageBrokerStats;

/**
 * Created by alex on 15-1-23.
 */
@Controller
public class GreetingController {

    @Autowired
    private WebSocketMessageBrokerStats stats;

    @MessageMapping("/helloMsg")
    //@SendTo("/topic/greetings")
    public String greeting(String message) throws Exception {
        //Thread.sleep(3000); // simulated delay
        //return new Greeting("Hello, " + message.getName() + "!");

        return "hello world";
    }
    
    @MessageMapping("/hello.{path}")
    public String hello(String message,@DestinationVariable("path") String path) throws Exception {
        return "Hello spring websocket";

    }
    
    @SubscribeMapping("/first")
    public String first() {
        return "first handle";
    }

    @RequestMapping("/stats")
    public @ResponseBody
    WebSocketMessageBrokerStats showStats() {
        return stats;
    }
}
